package com.jet.core.interceptor;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Slf4j
public class ExcelReadListener<T> extends AnalysisEventListener<T> {

    private final List<Map<Integer, String>> headList = new ArrayList<>();
    private final List<T> dataList = new ArrayList<>();

    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        log.info("解析到一条头数据:{}", headMap);
        headList.add(headMap);
    }

    @Override
    public void invoke(T t, AnalysisContext analysisContext) {
        log.info("解析到一条数据:{}", t);
        dataList.add(t);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        log.info("所有数据解析完毕");
    }


    public List<Map<Integer, String>> getHeadList() {
        return headList;
    }

    public List<T> getDataList() {
        return dataList;
    }
}
